import 'package:flutter/material.dart';
import 'package:bookapp/widgets/common/common_title.dart';
import 'package:bookapp/widgets/common/common_book_card.dart';
import 'package:fluro/fluro.dart';
import 'package:bookapp/routers/application.dart';
import 'package:bookapp/helpers/fluro_convert_util.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:bookapp/models/common.dart';
import 'package:provider/provider.dart';
import 'package:bookapp/stores/home_store.dart';


class PopularBooks extends StatelessWidget {
  const PopularBooks({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final homeStore = Provider.of<HomeStore>(
      context,
      listen:false,
    );

    return Column(
      children: <Widget>[
        SizedBox(height:32.0),
        CommonTitle(
          title: "最受欢迎",
          onTap: (){
            Application.getRouter().navigateTo(
              context,
              "/detail?title=${FluroConvertUtils.fluroCnParamsEncode('最受欢迎')}&type=popularBooks",
              transition:TransitionType.native,
            );
          },
        ),
        SizedBox(height:32.0),
        Observer(
          builder: (_) {
            List<CommonData> _popularBookData = homeStore.recommendData.data;
            return _popularBookData == null ?
                Text("正在获取数据") :
                Container(
                  height: 140.0,
                  child: ListView(
                    scrollDirection: Axis.horizontal,
                    children: _popularBookData.map(
                        (CommonData data) => Container(
                          margin: EdgeInsets.only(right: 16.0),
                          child: CommonBookCard(
                            boxWidth: 0.0,
                            title: data.title,
                            bookImage: data.bookImage,
                            description: data.description.trimLeft(),
                            author: data.author,
                          ),
                        )
                    ).toList(),
                  ),
                );
          },
        ),
      ],
    );
  }
}
